package com.old.people.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.old.people.entities.Account;
import com.old.people.entities.DieasePeople;
import com.old.people.service.ManagerServices;

@RestController
public class ManagerController {
	@Autowired
	private ManagerServices managerServices;
	
	@RequestMapping("/consumer/getAllAccount")
	@ResponseBody
	public List<Account> getAllAccount(@RequestParam("page") int page){
		return managerServices.accountManager(page);
	}
	
	@RequestMapping("/consumer/getPageSum")
	@ResponseBody
	public int getPageSum(){
		return managerServices.accountSumManager();
	}
	
	@RequestMapping("/consumer/updateAccountType")
	@ResponseBody
	public boolean updateAccountType(@RequestParam("account_id") String account_id,@RequestParam("account_type") String account_type) {
		return managerServices.updateAccountType(account_id, account_type);
	}
	
	@RequestMapping("/consumer/selectAccount")
	public Account selectAccount(@RequestParam("account_id")String account_id) {
		return managerServices.selectAccount(account_id);
	}
	
	@RequestMapping("/consumer/getDieasePeople")
	@ResponseBody
	public List<DieasePeople> getDieasePeople(Integer page){
		return managerServices.getDieasePeople(page);
	}

	@RequestMapping("/consumer/getDieasePeopleSum")
	@ResponseBody
	public Integer getDieasePeopleSum() {
		return managerServices.getDieasePeopleSum();
	}

	@RequestMapping("/consumer/selectDieasepeople")
	@ResponseBody
	public List<DieasePeople> selectDieasepeople(String oldpeople_name) {
		return managerServices.selectDieasepeople(oldpeople_name);
	}

	@RequestMapping("/consumer/updateAccount")
	@ResponseBody
	public boolean updateAccount(HttpServletRequest request,HttpServletResponse response,String account_password) {
		HttpSession session= request.getSession();
		String account_id=(String) session.getAttribute("account_id");
//		System.out.println(account_id);
		return managerServices.updateAccount(account_id, account_password);
	}
}
